﻿// YamlSurrogateSelector.cs
//
// Copyright 2008 by Burt Harris
// Licensed under the Microsoft Public License (Ms-PL)
// See: http://www.codeplex.com/yaml/license
//
using System;
using System.Runtime.Serialization;

namespace YaTools.Yaml.Serialization
{
    [Obsolete]
    class YamlSurrogateSelector : SurrogateSelector
    {
        public override ISerializationSurrogate GetSurrogate(Type type, StreamingContext context, out ISurrogateSelector selector)
        {
            selector = this;

            if (Globals.TypeOfIEnumerable.IsAssignableFrom(type))
                return EnumerableSurrogate.Instance;

            if (Globals.TypeOfIDictionary.IsAssignableFrom(type))
                return DictionarySurrogate.Instance;

            if (type.IsSerializable)
                return new RuntimeSerializationSurrogate(type);

            var result = base.GetSurrogate(type, context, out selector);
            if (result is YamlSurrogate)
                return result;

            if (result != null)
                return new SurrogateWrapper(result);

            return ConvertSurrogate.Instance;
        }
    }
}
